package com.charging.business.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.charging.business.exception.CustomizeException;
import com.charging.business.handle.FeeEnCalcHandle;
import com.charging.business.handle.FeeExCalcHandle;
import com.charging.business.vo.BasicRequest;
import com.charging.business.vo.BasicResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author JerryLu
 * @date 2024/8/16 16:21
 * @description 主控制器请求入口
 */
@RestController
@Slf4j
@RequestMapping(value = "/v1/main/fee")
public class MainController {

    @Autowired
    private FeeEnCalcHandle feeEnCalcHandle;

    @Autowired
    private FeeExCalcHandle feeExCalcHandle;

    /**
     * 入出口计费
     *
     * @param jsonObject
     * @return java.lang.String
     * @author JerryLu
     * @date 2024/8/26 9:14
     * @note BASIC_FEE_ENCALC_REQ_车道 HEX 编号_YYYYMMDDhhmmssSSS.json
     * 示例：BASIC_FEE_ENCALC_REQ_1104201101_20200909231223111.json
     */
    @RequestMapping
    public BasicResponse laneCalc(@RequestBody JSONObject jsonObject) throws CustomizeException {
        BasicRequest publicRequest = JSON.parseObject(jsonObject.toString(), BasicRequest.class);
        BasicResponse result;
        if (publicRequest.getFilename().contains("BASIC_FEE_ENCALC")) {
            result = feeEnCalcHandle.handle(jsonObject);
        } else {
            result = feeExCalcHandle.handle(jsonObject);
        }
        return result;
    }
}
